package com.system.goods.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.bean.Type;
import com.system.common.service.ITypeService;
import com.system.common.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/type")
public class TypeController {

    @DubboReference
    private ITypeService typeService;
@PostMapping("/add")
public Result add(@RequestBody Type type){
    typeService.addType(type);
    return Result.ok("添加类型成功");
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        typeService.deleteType(id);
        return Result.ok("删除类型成功");
    }
    @PutMapping("/update")
    public Result update(@RequestBody Type type){
        typeService.updateType(type);
        return Result.ok("修改类型成功");
    }
    @GetMapping("/list")
    public Result list(){
        return Result.ok(typeService.getTypeList());
    }
    @GetMapping("/page")
    public Result page(Type type,@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize){
        return Result.ok("获取类型列表成功",typeService.getPage(type, new Page<>(pageNum, pageSize)));
    }
    @GetMapping("/getTypeById/{id}")
    public Result getTypeById(@PathVariable Integer id){
        return Result.ok("获取类型成功",typeService.getTypeById(id));
    }
}


